package com.yc.study.controller;


import com.yc.study.entity.StudentCheckInLog;
import com.yc.study.entity.User;
import com.yc.study.service.IStudentCheckInLogService;
import com.yc.study.service.IUserService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * <p>
 * 学生签到记录表 前端控制器
 * </p>
 *
 * @author 王妍
 * @since 2022-05-16
 */
@RestController
@RequestMapping("/study/studentCheckInLog")
@AllArgsConstructor
public class StudentCheckInLogController {

    private final IStudentCheckInLogService studentCheckInLogService;

    private final IUserService userService;
    @PostMapping
    public  void save(Principal principal, @RequestBody StudentCheckInLog studentCheckInLog){
        final String name = principal.getName();
        final User user = userService.loadUserByUserName(name);
        studentCheckInLog.setStudentId(user.getId());
        studentCheckInLogService.save(studentCheckInLog);
    }

}

